import { request, config } from 'utils'

const { api } = config
const { customerPhoneList, customerPhoneAdd, customerPhoneEdit, customerPhoneDel, accoutSignPhoneList, accoutSignPhoneAdd, accoutSignPhoneEdit, accoutSignPhoneDel, entityPhoneList, entityPhoneAdd, entityPhoneEdit, entityPhoneDel } = api
const { entityDirectorPhoneList, entityDirectorPhoneAdd, entityDirectorPhoneEdit, entityDirectorPhoneDel } = api
const { reportBasePhoneList, reportBasePhoneAdd, reportBasePhoneEdit, reportBasePhoneDel  } = api

function apiSelect (type) {
  let phoneApi = {}
  switch (type) {
    case 'customerPhone':
      phoneApi.listAPI = customerPhoneList
      phoneApi.createAPI = customerPhoneAdd
      phoneApi.updateAPI = customerPhoneEdit
      phoneApi.delAPI = customerPhoneDel
      break
    case 'signPhone':
      phoneApi.listAPI = accoutSignPhoneList
      phoneApi.createAPI = accoutSignPhoneAdd
      phoneApi.updateAPI = accoutSignPhoneEdit
      phoneApi.delAPI = accoutSignPhoneDel
      break
    case 'entityPhone':
      phoneApi.listAPI = entityPhoneList
      phoneApi.createAPI = entityPhoneAdd
      phoneApi.updateAPI = entityPhoneEdit
      phoneApi.delAPI = entityPhoneDel
      break
    case 'entityDirectorPhone':
      phoneApi.listAPI = entityDirectorPhoneList
      phoneApi.createAPI = entityDirectorPhoneAdd
      phoneApi.updateAPI = entityDirectorPhoneEdit
      phoneApi.delAPI = entityDirectorPhoneDel
      break
    case 'reportBasePhone':
      phoneApi.listAPI = reportBasePhoneList
      phoneApi.createAPI = reportBasePhoneAdd
      phoneApi.updateAPI = reportBasePhoneEdit
      phoneApi.delAPI = reportBasePhoneDel
      break
    default:
  }
  return phoneApi
}
export async function list (params) {
  const { listAPI } = apiSelect(params.type)
  return request({
    url: listAPI,
    method: 'put',
    data: params,
  })
}

export async function create (params) {
  const { createAPI } = apiSelect(params.type)
  return request({
    url: createAPI,
    method: 'post',
    data: params.data,
  })
}

export async function update (params) {
  const { updateAPI } = apiSelect(params.type)
  return request({
    url: updateAPI,
    method: 'put',
    data: params.data,
  })
}
export async function remove (params) {
  const { delAPI } = apiSelect(params.type)
  return request({
    url: delAPI,
    method: 'delete',
    data: params,
  })
}

